<template>
  <div class="block">
    <el-button
        type="primary"
        @click="openAlert"
    >新增</el-button>
    <el-dialog
        title="信息"
        :visible.sync="alertShow"
        width="700px"
        append-to-body
        :close-on-press-escape="false"
        :close-on-click-modal="false"
        @close="cancelAlert"
    >
      <lazyCascader v-model="depart_check" :props="defaultProps" clearable/>
    </el-dialog>
  </div>
</template>

<script>
import lazyCascader from "./LazyCascader.vue";

import axios from 'axios';
export default {
  components: {lazyCascader},
  data() {
    return {      
      depart_check: [[1,2,3], [1,2,7]],//一维回显展示，但是没有选中的状态         
      defaultProps: {
        multiple: true,//多选
        checkStrictly: true,
        lazy: true,
        lazyLoad: this.lazyLoad.bind(this),
        value: "value",
        label: "label",
      },

      alertShow: false,
    };
  },
  methods: {
    async lazyLoad(node, resolve) {
      let nodes = []
      if (node == 0) {
        axios({
          url: "https://d7u7100584.goho.co/elderly_rest_war/sys/area/list",
          params: {leve: 1},
        }).then(response => {
          nodes = response.data.rows.map((item) => {
            let obj = {
              value: item.id,
              label: item.name,
              leaf: false
            };
            return obj
          });
          console.log('>>>请求一级数据', nodes)
          resolve(nodes);
        })
        return nodes
      } else {
        let obj = {
          parentId: node,
          currPage: 0,
          pageSize: 0,
        };
        axios({
          url: "https://d7u7100584.goho.co/elderly_rest_war/sys/area/list",
          params: obj,//传参
        }).then(response => {
          if (response.data.rows) {
            nodes = response.data.rows.map((item) => {
              let obj = {
                value: item.id,
                label: item.name,
                // leaf: node.level >= 2,
                leaf: item.leve === '3',
              };
              return obj
            });
            resolve(nodes);
          } else {
            resolve([]);
          }
          console.log('>>>>请求子级数据', nodes)
          return nodes
        })
      }
    },
    cascaderChange(e) {
      console.log(e)
    },
    openAlert() {
      this.alertShow = true;
    },
    cancelAlert() {
      this.alertShow = false;
    }
  }
};
</script>

<style>
</style>